package ace.j2se.l1;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public abstract class AbsModelDriven implements ModelDriven {

	public void save() throws SecurityException, NoSuchFieldException,
			NoSuchMethodException, IllegalArgumentException,
			IllegalAccessException, InvocationTargetException {
		Object object = getModel();
		Class clz = object.getClass();
		Field field = clz.getDeclaredField("name");
		// String setName = "set" + field.getName().substring(0).toUpperCase()
		// + field.getName().substring(1);
		String getName = "get" + field.getName().substring(0, 1).toUpperCase()
				+ field.getName().substring(1);
		Method getMethod = clz.getMethod(getName, new Class[] {});
		Object value = getMethod.invoke(object, new Object[] {});
		System.out.println(value);
		System.out.println(getModel());
	}

}
